package cn.pet.service.manage.service.impl;

import cn.pet.service.manage.entity.PetGoods;
import cn.pet.service.manage.entity.dto.GoodsDTO;
import cn.pet.service.manage.entity.vo.GoodTypeList;
import cn.pet.service.manage.entity.vo.GoodsVO;
import cn.pet.service.manage.mapper.PetGoodsMapper;
import cn.pet.service.manage.service.PetGoodsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 商品信息表 服务实现类
 * </p>
 *
 * @author 
 * @since 2023-02-11
 */
@Service
public class PetGoodsServiceImpl extends ServiceImpl<PetGoodsMapper, PetGoods> implements PetGoodsService {

    @Resource
    private PetGoodsMapper petGoodsMapper;

    @Value("${pet.downloadUrl}")
    private String downloadUrl;

    @Override
    public List<GoodsVO> listByPage(GoodsDTO goodsDTO) {
        PageHelper.startPage(goodsDTO.getPageNum(),goodsDTO.getPageSize());
        List<GoodsVO> goodsVOS = petGoodsMapper.listByLimit(goodsDTO);
        for (GoodsVO vo: goodsVOS){
            vo.setPicture(downloadUrl+"/"+vo.getId());
        }
        return goodsVOS;
    }

    @Override
    public GoodsVO getDetail(Integer id) {
        return petGoodsMapper.queryById(id);
    }

    @Override
    public List<GoodTypeList> getTypeAndGoods() {
        List<GoodTypeList> goodTypeLists = this.baseMapper.typeAndGoods();
        for (GoodTypeList goodTypeList : goodTypeLists){
            List<GoodsVO> goods = goodTypeList.getGoods();
            for (GoodsVO vo : goods){
                vo.setPicture(downloadUrl+"/"+vo.getId());
            }
        }
        return goodTypeLists;
    }
}
